﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

using FirstFloor.Documents.Services.Storage;

namespace FirstFloor.Documents.Services.RequestHandlers
{
    /// <summary>
    /// Converts uploaded documents to XPS on-the-fly using Aspose.Words and writes the entire result XPS document to the output.
    /// </summary>
    public class ConvertToXpsHandler
        : IRequestHandler
    {
        /// <summary>
        /// Handles the request.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="store">The store.</param>
        public void HandleRequest(HttpContext context, IDocumentStore store)
        {
            // limit requests to 512kb
            if (context.Request.ContentLength > 2 << 18) {
                throw new NotSupportedException();
            }


            //
            // Aspose.Words assembly not included.
            //
            // Instructions
            //  1) Download evaluation of this commercial product from http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx.
            //  2) Add reference to Aspose.Words binary in project FirstFloor.Documents.Services
            //  3) Uncomment lines below, remove throw exception
            //  4) Compile and run
            //
            // Note: Aspose is not affiliated with First Floor Software
            //
            //

            throw new Exception("Aspose.Words assembly not included");

            // load document
            //var document = new Aspose.Words.Document(context.Request.InputStream);
            // convert to XPS
            //document.Save(context.Response.OutputStream, Aspose.Words.SaveFormat.Xps);
        }
    }
}
